﻿using Dapper;
using System.Data;

namespace PoemGame.Query.Dapper
{
    public class GamePlayRecordQuery:IGamePlayRecordQuery
    {
        private readonly IDbConnection connection;

        public GamePlayRecordQuery(IDbConnection connection)
        {
            this.connection = connection;
        }
        public async Task<IEnumerable<GamePlayRecordRes>> GetRecordsByGameAsync(
            Guid gameId)
        {
            return await connection.GetListAsync<GamePlayRecordView>("where GameId='" + gameId+"'"); 
        }

        public async Task<IEnumerable<GamePlayRecordRes>> GetRecordsByPlayerAsync(
            Guid playerId)
        {
            return await connection.GetListAsync<GamePlayRecordView>("where GameId='" + playerId + "'"); ;
        }

        public async Task<IEnumerable<GamePlayRecordRes>> GetRecordsByConditionAsync(
            string wherecondition)
        {
            return await connection.GetListAsync<GamePlayRecordView>(wherecondition);
        }

        public async Task<IEnumerable<GamePlayRecordRes>> GetPagedRecordsByConditionAsync(
            int pageindex, 
            int pagesize, 
            string wherecondition, 
            string orderby)
        {
            return await connection.GetListPagedAsync<GamePlayRecordRes>(
                pageindex, pagesize, wherecondition, orderby);
        }

        public async Task<long> GetRecordsCountByConditionAsync(
            string wherecondition)
        {
            return await connection.RecordCountAsync<GamePlayRecordView>(wherecondition);
        }
    }
}
